<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>替换输入字符颜色</title>
  </head>
  <body>
    <div class="content">houdunren.com</div>
  </body>
  <script>
    let con = prompt("请输入需要检测的内容，支持正则");
    let reg = new RegExp(con, "g");
    let div = document.querySelector("div");
    div.innerHTML = div.innerHTML.replace(reg, (search) => {
      return `<span style="color:red">${search}</span>`;
    });
  </script>
</html>
